package com.cqrcb.cloud.service.quota;

import com.cqrcb.cloud.entity.quota.CustomerMultiQuotaCtrlDetail;
import com.cqrcb.cloud.mapper.quota.CustomerMultiQuotaCtrlDetailMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
* CustomerMultiQuotaCtrlDetailImpl
*
* @author 系统
* @date 2021-06-22 08:30:46
*/
@Service
public class CustomerMultiQuotaCtrlDetailImpl implements CustomerMultiQuotaCtrlDetailService {
    @Autowired
    private CustomerMultiQuotaCtrlDetailMapper customerMultiQuotaCtrlDetailMapper;

    @Autowired
    private CustomerMultiQuotaCtrlMainService customerMultiQuotaCtrlMainService;

    @Override
    public int deletes(List<CustomerMultiQuotaCtrlDetail> rmMultiQuotaCtrlMarketDetails) {
        if(!CollectionUtils.isEmpty(rmMultiQuotaCtrlMarketDetails)){
            List<Long> rmIds = rmMultiQuotaCtrlMarketDetails.stream().map(u -> u.getMultiDetailNo()).collect(Collectors.toList());
            return customerMultiQuotaCtrlDetailMapper.deleteByPrimaryKeys(rmIds);
        }
        return 0;
    }

    @Override
    public int adds(List<CustomerMultiQuotaCtrlDetail> newMultiQuotaCtrlMarketDetails) {
        int i = 0;
        if(!CollectionUtils.isEmpty(newMultiQuotaCtrlMarketDetails)){
            for (CustomerMultiQuotaCtrlDetail newMultiQuotaCtrlMarketDetail : newMultiQuotaCtrlMarketDetails) {
                i += customerMultiQuotaCtrlDetailMapper.insertSelective(newMultiQuotaCtrlMarketDetail);
            }
        }
        return i;
    }

    @Override
    public int updates(List<CustomerMultiQuotaCtrlDetail> newMultiQuotaCtrlMarketDetails) {
        int i = 0;
        if(!CollectionUtils.isEmpty(newMultiQuotaCtrlMarketDetails)){
            for (CustomerMultiQuotaCtrlDetail newMultiQuotaCtrlMarketDetail : newMultiQuotaCtrlMarketDetails) {
                int i1 = customerMultiQuotaCtrlDetailMapper.updateByPrimaryKeySelective(newMultiQuotaCtrlMarketDetail);
                if(i1 <= 0) {
                    i1 = customerMultiQuotaCtrlDetailMapper.insertSelective(newMultiQuotaCtrlMarketDetail);
                }
                i += i1;
            }
        }
        return i;
    }
}
